<?php if (!defined("_ECRIRE_INC_VERSION")) return;
/**
 * Aloha Cart
 *
 * @author     Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 * @license    GNU/GPL
 * @package    plugins
 * @subpackage alohacart
 * @copyright  (c) Aleksey Yaroshchuk 2011-2012
 * @link       http://www.spip-contrib.net/AlohaCart
 */

include_spip('functions/pdk_common');

function formulaires_alohacart_extension_verifier_dist($id_extension){
	$erreurs = array();
    
    $extension_mdl = pdk_load_class('AlohacartExtensionModel','classes');
    $extension = $extension_mdl->GetExtensionClassByID($id_extension);
    
    $data = array();
    foreach ($extension->fields as $field) {                
        $data[$field] = _request('extension_'.$field);  
    }
    
    // Extension validation
    $extension->validation->Validate($data, $erreurs_extension);
    
    foreach ($erreurs_extension as $field=>$error) {
        $erreurs_extension['extension_'.$field] = $erreurs_extension[$field];
        unset($erreurs_extension[$field]);
    }
    
    //Extension model validation
    $data = $extension_mdl->form_data_from_array($_REQUEST);
    $extension_mdl->validate($data, $erreurs_extension_mdl, true);
    
    // Return all errors
    $erreurs = array_merge($erreurs_extension, $erreurs_extension_mdl);
    
    if (count($erreurs))
        $erreurs['message_erreur'] = _T('pdk:validation_message_error');
     
	return $erreurs;
}